package com.shujia.array;

import java.util.Arrays;

public class Homework1 {

    public static void main(String[] args) {
        int[] arr = {5, 8, 6, 3, 9, 2, 1, 7};
        System.out.println("排序前的:" + Arrays.toString(arr));
        bubbleSort(arr);
        System.out.println("排序后的:" + Arrays.toString(arr));
    }

    // 排序的是数组
    public static void bubbleSort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    // 交换元素
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }
}
